<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../layui-v2.2.6/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="../../css/font_eolqem241z66flxr.css" media="all" />
    <script src="../../jquery-3.3.1/jquery-3.3.1.min.js"></script>
    <script src="../../jquery-3.3.1/jquery-3.3.1.js"></script>

    <script type="text/javascript" src="../../../tool/ajax.js"></script>
</head>
<body class="childrenBody">
<form class="layui-form" style="display: flex;flex-direction: column;align-content: center;margin-top: 20px">

    <div class="layui-form-item">
        <label class="layui-form-label">旧密码</label>
        <div class="layui-input-block">
            <input type="text" id="pwd" class="layui-input newsName" lay-verify="required"  style="width: 400px" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-block">
            <input type="text" id="newpwd" class="layui-input newsName" lay-verify="required"  style="width: 400px" >
        </div>
    </div>


    <button type="button" align="center"  onclick="editpro()"  style="width:100px;margin-left: 260px" class="layui-btn layui-btn-normal layui-btn-radius">提交
    </button>

</form>
<script type="text/javascript" src="../../../layui-v2.2.6/layui/layui.js"></script>
</body>
<script>
    function editpro() {
        var base64=new Base64();
        var pwd = base64.encode(document.getElementById("pwd").value);
        var newpwd = base64.encode(document.getElementById("newpwd").value);

        var token=getCookieValue("token");

        ajaxget("system/changePwd", {pwd:pwd,newpwd:newpwd,token:token}, function (data) {
            try {
                console.log("服务器请求会发")
                if (data.code == 200) {
                    layer.msg('密码修改成功', {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        parent.location.reload();
                    });
                } else {
                    layer.msg(data.msg, {
                        icon: 0,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {

                        // parent.location.reload();
                    });
                }
            } catch (e) {
                layer.msg('修改失败', {
                    icon: 0,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function () {
                    // parent.location.reload();
                });
            }
        })


    }


    layui.use('upload', function(){


        var $ = layui.jquery
            ,upload = layui.upload;
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: 'http://ty108.com/dazhuanpan/upload/img'
            ,done: function(res){
                console.log(res)
                //如果上传失败
                if(res.code ==200){
                    $("#demoText").val(res.data.path)
                    return layer.msg('上传成功');

                }else {
                    return layer.msg('上传失败');
                }
                //上传成功
            }

            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#img').attr('src', result); //图片链接（base64）
                });
            }

            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });


    });


    function getCookieValue(name) {

        var strCookie=document.cookie;

        var arrCookie=strCookie.split(";");

        for(var i=0;i<arrCookie.length;i++){

            var c=arrCookie[0].split("=");

            if(c[0]==name){

                return c[1];

            }

        }

        return "";

    }


    function Base64() {

        // private property
        _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

        // public method for encoding
        this.encode = function (input) {
            var output = "";
            var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
            var i = 0;
            input = _utf8_encode(input);
            while (i < input.length) {
                chr1 = input.charCodeAt(i++);
                chr2 = input.charCodeAt(i++);
                chr3 = input.charCodeAt(i++);
                enc1 = chr1 >> 2;
                enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
                enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
                enc4 = chr3 & 63;
                if (isNaN(chr2)) {
                    enc3 = enc4 = 64;
                } else if (isNaN(chr3)) {
                    enc4 = 64;
                }
                output = output +
                    _keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
                    _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
            }
            return output;
        }

        // public method for decoding
        this.decode = function (input) {
            var output = "";
            var chr1, chr2, chr3;
            var enc1, enc2, enc3, enc4;
            var i = 0;
            input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
            while (i < input.length) {
                enc1 = _keyStr.indexOf(input.charAt(i++));
                enc2 = _keyStr.indexOf(input.charAt(i++));
                enc3 = _keyStr.indexOf(input.charAt(i++));
                enc4 = _keyStr.indexOf(input.charAt(i++));
                chr1 = (enc1 << 2) | (enc2 >> 4);
                chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
                chr3 = ((enc3 & 3) << 6) | enc4;
                output = output + String.fromCharCode(chr1);
                if (enc3 != 64) {
                    output = output + String.fromCharCode(chr2);
                }
                if (enc4 != 64) {
                    output = output + String.fromCharCode(chr3);
                }
            }
            output = _utf8_decode(output);
            return output;
        }

        // private method for UTF-8 encoding
        _utf8_encode = function (string) {
            string = string.replace(/\r\n/g,"\n");
            var utftext = "";
            for (var n = 0; n < string.length; n++) {
                var c = string.charCodeAt(n);
                if (c < 128) {
                    utftext += String.fromCharCode(c);
                } else if((c > 127) && (c < 2048)) {
                    utftext += String.fromCharCode((c >> 6) | 192);
                    utftext += String.fromCharCode((c & 63) | 128);
                } else {
                    utftext += String.fromCharCode((c >> 12) | 224);
                    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                    utftext += String.fromCharCode((c & 63) | 128);
                }

            }
            return utftext;
        }

        // private method for UTF-8 decoding
        _utf8_decode = function (utftext) {
            var string = "";
            var i = 0;
            var c = c1 = c2 = 0;
            while ( i < utftext.length ) {
                c = utftext.charCodeAt(i);
                if (c < 128) {
                    string += String.fromCharCode(c);
                    i++;
                } else if((c > 191) && (c < 224)) {
                    c2 = utftext.charCodeAt(i+1);
                    string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                    i += 2;
                } else {
                    c2 = utftext.charCodeAt(i+1);
                    c3 = utftext.charCodeAt(i+2);
                    string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                    i += 3;
                }
            }
            return string;
        }
    }


</script>
</html>